class Layer < ActiveRecord::Base
  acts_as_list 
  
  has_many :shapes
  belongs_to :style
  
  def Layer.create_from_shp(file, attrs = {})
    sf = ShapeFile.new(file)
    layer = nil
    Layer.transaction do
      layer = Layer.new(attrs)
      for shp in sf.shapes
        shape = layer.shapes.create(layer.attributes.keep(:style_id, :title_attribute, 
                                            :zoom_min, :zoom_max))
        shape.load_from_shp(shp, sf.fields)
      end
      layer.save
    end
    layer
  end
  
end